import { getAction, putAction, postAction } from '@/api/manage'
import { api as userApi } from '../user/service.js'
import { serviceApi } from '@/api/common.js'
/**
 * 公共API接口
 */
export const api = {
  list: serviceApi.auth + '/roles/app-roles',
  listEnable: serviceApi.auth + '/roles/app-roles-enable',
  delete: (ids) => serviceApi.auth + `/roles/app-role/${ids}`,
  userList: userApi.userList
}

/**
 * 添加应用角色
 * @param params
 * @returns {AxiosPromise}
 */
export const addRole = params => postAction(serviceApi.auth + '/roles/app-role', params);

/**
 * 编辑应用角色
 * @param {*} params
 * @returns
 */
export const editRole = params => putAction(serviceApi.auth + '/roles/app-role', params);

/**
 * 应用下是否存在默认应用角色
 * @param appId
 * @param params
 * @returns {AxiosPromise}
 */
export const queryDefaultByAppId = (appId, params) => getAction(serviceApi.auth + `/roles/exist-default/apps/${appId}`, params);

/**
 * 重复校验应用角色编码，名称是否应用下唯一接口
 * @param appId
 * @param params
 * @returns {AxiosPromise}
 */
export const checkAppRole = (params) => getAction(serviceApi.auth + '/duplicate/check-app-role', params);

/**
 * 获取菜单树形列表
 * @param {*} params
 * @returns
 */
export const queryPermissionTree = (appId, roleId, params) => getAction(serviceApi.auth + `/roles/${roleId}/apps/${appId}/tree`, params);

/**
 * 应用角色授权
 * @param params
 * @returns {AxiosPromise}
 */
export const saveAppRolePermission = (params) => postAction(serviceApi.auth + '/permissions/app-role-permission', params);
/**
 * 组织内应用角色启用
 * @param params
 * @returns {AxiosPromise}
 */
export const appRoleEnable = (tenantId, params) => postAction(serviceApi.auth + `/roles/tenants/${tenantId}/app-role-enable`, params);

/**
 * 组织内应用角色禁用
 * @param params
 * @returns {AxiosPromise}
 */
export const appRoleDisable = (tenantId, params) => postAction(serviceApi.auth + `/roles/tenants/${tenantId}/app-role-disable`, params);

/**
 * 应用角色启用禁用
 * @param params
 * @returns {AxiosPromise}
 */
export const startUsing = params => putAction(serviceApi.auth + '/roles/app-role/start-using', params);
